#include "Stdafx.h"
#include "TextureResource.h"

namespace WindGE
{
	TextureResource::TextureResource()
		: shader_reflection_(nullptr)
		, is_array_(false)
	{
	}

	TextureResource::~TextureResource()
	{
	}

	void TextureResource::create(ID3D11ShaderReflection* shaderReflection, const D3D11_SHADER_INPUT_BIND_DESC& inputBindDesc)
	{
		shader_reflection_ = shaderReflection;
		
		shader_bind_ = std::make_shared<ShaderBind>();
		shader_bind_->create(shader_reflection_, inputBindDesc);

		is_array_ = (inputBindDesc.Dimension == D3D_SRV_DIMENSION_TEXTURE1DARRAY) ||
					(inputBindDesc.Dimension == D3D_SRV_DIMENSION_TEXTURE2DARRAY) ||
					(inputBindDesc.Dimension == D3D_SRV_DIMENSION_TEXTURE2DMSARRAY) ||
					(inputBindDesc.Dimension == D3D_SRV_DIMENSION_TEXTURECUBEARRAY);

		type_ = e_tex_unknown;
		switch (inputBindDesc.Dimension)
		{
		case D3D_SRV_DIMENSION_TEXTURE1D:
			type_ = e_tex_1d;
			break;
		case D3D_SRV_DIMENSION_TEXTURE1DARRAY:
			type_ = e_tex_1d_array;
			break;
		case D3D_SRV_DIMENSION_TEXTURE2D:
			type_ = e_tex_2d;
			break;
		case D3D_SRV_DIMENSION_TEXTURE2DARRAY:
			type_ = e_tex_2d_array;
			break;
		case D3D_SRV_DIMENSION_TEXTURE2DMS:
			type_ = e_tex_2dms;
			break;
		case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY:
			type_ = e_tex_2dms_array;
			break;
		case D3D_SRV_DIMENSION_TEXTURE3D:
			type_ = e_tex_3d;
			break;
		case D3D_SRV_DIMENSION_TEXTURECUBE:
			type_ = e_tex_cube;
			break;
		case D3D_SRV_DIMENSION_TEXTURECUBEARRAY:
			type_ = e_tex_cube_array;
			break;
		default:
			break;
		}
	}

}//end namespace WindGE

